//
//  ViewController.swift
//  02.表情键盘
//
//  Created by yaochunlin on 16/4/21.
//  Copyright © 2016年 yaochunlin. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textView: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        textView.inputView = emoticonKeyboard
        
    }
    
    //MARK 懒加载表情键盘
    private lazy var emoticonKeyboard:YCLEmoticonKeyboard = {
    
        let view = YCLEmoticonKeyboard()
        
        view.frame = CGRect.init(origin: CGPointZero, size: CGSize.init(width: UIScreen.mainScreen().bounds.width, height: 216))
        
        view.textView = self.textView
        
        return view
    }()
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
        let strM = textView.emoticonText()
        print("strM: \(strM)")
        
////        print("获取text文本 \(textView.attributedText)")
//        //获取属性文本的每一段
//        
//        var strM = ""
//        
//        //遍历获取属性文本的每一段
//        textView.attributedText.enumerateAttributesInRange(NSRange.init(location: 0, length: textView.attributedText.length), options: []) { (dict, range, _) in
//            
//            //判断是否为附件
//            if let attachment = dict["NSAttachment"] as? YCLTextAttachment {
//            
//                strM += attachment.chs!
//            }else{
//            
//                let text = (self.textView.attributedText.string as NSString).substringWithRange(range)
//                
//                strM += text
//            }
//            
//            print("dict:\(dict)")
//            print("range:\(range)")
//            print("----------")
//            
//        }
//        
//        print("strm:\(strM)")
//        
    }


}

